package com.credit.jumu.playcard.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.credit.jumu.playcard.R;
import com.credit.jumu.playcard.bean.HomeListInfo;
import com.credit.jumu.playcard.bean.ProInfo;
import com.credit.jumu.playcard.utils.GlideUtil;
import com.credit.jumu.playcard.utils.ToastUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/10/18/018.
 */

public class HomeProListAdapter extends BaseAdapter {
	private Context context;
	private List<HomeListInfo> mlistInfo = new ArrayList<HomeListInfo>();
	public GoMoneyOnClick goMoneyOnClick;

	public HomeProListAdapter(List<HomeListInfo> mlistInfo, Context context, GoMoneyOnClick goMoneyOnClick) {
		this.context = context;
		this.mlistInfo = mlistInfo;
		this.goMoneyOnClick = goMoneyOnClick;

	}

	public interface GoMoneyOnClick {
		public void GoMoney(String id);
	}

	class ChooseCameraClick implements View.OnClickListener {
		@Override
		public void onClick(View v) {
			if (goMoneyOnClick != null) {
				goMoneyOnClick.GoMoney(v.getTag().toString());
			}
		}
	}


	@Override
	public int getCount() {
		return mlistInfo.size();
	}

	@Override
	public Object getItem(int position) {
		return mlistInfo.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder = null;
		if (null == viewHolder) {
			LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = inflater.inflate(R.layout.item_home, null);
			viewHolder = new ViewHolder();
			viewHolder.proicon = convertView.findViewById(R.id.proicon);//图标
			viewHolder.protext = (TextView) convertView.findViewById(R.id.protext);
			viewHolder.moneymax = (TextView) convertView.findViewById(R.id.moneymax);
			viewHolder.longmaxtime = (TextView) convertView.findViewById(R.id.longmaxtime);
			viewHolder.interest = (TextView) convertView.findViewById(R.id.interest);
			viewHolder.proshow = (TextView) convertView.findViewById(R.id.proshow);
			viewHolder.peoplenum = (TextView) convertView.findViewById(R.id.peoplenum);
			viewHolder.myshowicon = (ImageView) convertView.findViewById(R.id.myshowicon);
			viewHolder.cilckbut = convertView.findViewById(R.id.cilckbut);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		GlideUtil.loadImage(context, mlistInfo.get(position).getProicon(), viewHolder.proicon);
		viewHolder.protext.setText(mlistInfo.get(position).getProtext());
		viewHolder.moneymax.setText(mlistInfo.get(position).getMoneymax());
		viewHolder.longmaxtime.setText("期限：" + mlistInfo.get(position).getLongmaxtime());
		viewHolder.interest.setText("参考利率：" + mlistInfo.get(position).getInterest());
		viewHolder.proshow.setText(mlistInfo.get(position).getProshow());
		viewHolder.peoplenum.setText(mlistInfo.get(position).getPeoplenum());
		if (0 <= position && position < 3) {
			viewHolder.myshowicon.setVisibility(View.VISIBLE);
			viewHolder.myshowicon.setImageResource(R.mipmap.rec);
		} else if (3 <= position && position < 6) {
			viewHolder.myshowicon.setImageResource(R.mipmap.hot);
			viewHolder.myshowicon.setVisibility(View.VISIBLE);
		} else if (6 <= position && position < 9) {
			viewHolder.myshowicon.setVisibility(View.VISIBLE);
			viewHolder.myshowicon.setImageResource(R.mipmap.new_icon);
		} else {
			viewHolder.myshowicon.setVisibility(View.GONE);
		}
		viewHolder.cilckbut.setTag(mlistInfo.get(position).getProid());
		viewHolder.cilckbut.setOnClickListener(new ChooseCameraClick());
		return convertView;
	}

	private class ViewHolder {
		private ImageView proicon;
		private TextView protext;
		private TextView moneymax;
		private TextView longmaxtime;
		private TextView interest;
		private TextView proshow;
		private TextView peoplenum;
		private ImageView myshowicon;
		private TextView cilckbut;
	}
}

